extends HBoxContainer

@export var tilte:String = ""

@onready var _input:LineEdit = $"TextEdit"
@onready var _addBtn:Button = $"Add"
@onready var _subBtn:Button = $"Sub"

var _value = 0

signal on_value_changed(value)

# Called when the node enters the scene tree for the first time.
func _ready():
	$"Label".text = tilte
	
	_addBtn.button_down.connect(_on_button_down_addBtn)
	_subBtn.button_down.connect(_on_button_down_subBtn)
	_input.text_changed.connect(_on_text_changed_input)
	
	init_value(0)
	pass # Replace with function body.


func _on_text_changed_input(arg):
	if not arg.is_valid_int():
		_input.text = str(_value)
		return
		
	_value = arg.to_int()
	on_value_changed.emit(_value)


func _on_button_down_addBtn():
	_value = _value + 1
	_input.text = str(_value)
	on_value_changed.emit(_value)
	pass


func _on_button_down_subBtn():
	_value = _value - 1
	_input.text = str(_value)
	on_value_changed.emit(_value)
	pass

func init_value(value):
	_value = value
	_input.text = str(_value)
	pass
	

func change_value(value):
	_value = value
	_input.text = str(_value)
	on_value_changed.emit(_value)


func get_value():
	return _value;
